# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2023/12/19 14:39

from selenium.webdriver.common.by import By
from datetime import datetime,timedelta

# 获取当前日期时间
now = datetime.now()

# 计算前一天的日期
one_day_ago = now - timedelta(days=1)

# 将前一天的日期转换为字符串
one_day_ago_str = one_day_ago.strftime('%Y-%m-%d')

print("前一天的日期是:", one_day_ago_str)



class OrdersLocator:
    # 等待提交动画
    wait_for_submit = (By.CSS_SELECTOR, '[class="antd4-spin-dot antd4-spin-dot-spin"]')

    # orders 菜单
    orders_tab = (By.CSS_SELECTOR, '[path="/work_bench/userCenter/order/order"]')

    # 打开orders菜单成功展示元素
    orders_seccess = (By.CSS_SELECTOR, '[class="antd4-space-item"]')

    # 选择日期组建
    # 搜索条件resource package id
    resource_package_id = (By.ID, 'resourcePackageId')
    # 查询按钮
    resource_package_search = (By.CSS_SELECTOR, '[class ="antd4-btn antd4-btn-primary"]')

    # Total items
    orders_total_items = (By.CSS_SELECTOR, '[class="antd4-pagination-total-text"]')

    # class="antd4-btn antd4-btn-link table-operation-btnLine-btn"
    # 点击第一条order 的 view detail
    orders_view_detail = (By.XPATH,
                          '(//*[text()="View Detail"])[1]/..')

    # 第一条数据的 order id
    orders_select_num1 = (By.XPATH,
                          '(//*[@class="antd4-table-tbody"]//div[@class="cre-table-nowrap"]/a)[1]')
    # 第一条数据的 order type
    order_type_select_num1 = (By.XPATH,'(//*[@class="antd4-table-tbody"]//div[@class="cre-table-nowrap"])[2]')

    # 获取订单页面订单号 class="antd4-space-item"
    order_check_order = (By.CSS_SELECTOR, '[class="antd4-space-item"]')

    # order页面返回键盘
    order_return = (By.XPATH, '//*[@id="root"]/section/section/main/div/main/div/div/div/div[2]/div/div[1]/span[1]')

    # 查询选择条件  class="antd4-select antd4-select-in-form-item antd4-select-status-success antd4-select-single antd4-select-show-arrow"
    # order_select_terms = (By.CSS_SELECTOR,'[class="antd4-select-selection-item"]')
    order_select_terms = (By.XPATH,
                          '//*[@title="Order ID"]/../span[1]')

    # 下拉选择 Product Name  /html/body/div[5]/div/div/div/div[2]/div/div/div/div[2]
    # term_product_name = (By.CSS_SELECTOR, '[class="antd4-select-item-option-content"]')
    term_product_name = (By.XPATH, '(//div[@title="Product Name"])[1]')

    #
    # class="antd4-select-selection-placeholder"
    term_product_name1 = (By.CSS_SELECTOR, '[class="antd4-select-selection-placeholder"]')

    # 时间选择框
    # class="antd4-picker-input antd4-picker-input-active"
    order_time = (By.CSS_SELECTOR,'[class="antd4-picker-input antd4-picker-input-active"]')

    #选择开始时间title="2023-12-25"
    now = datetime.now()
    one_day_ago = now - timedelta(days=1)
    now_str = now.strftime('%Y-%m-%d')
    now_str1 = now.strftime('%m-%d-%Y')
    content = '[title="'+now_str+'"]'
    order_select_time = (By.CSS_SELECTOR,content)

    now_str_yes= one_day_ago.strftime('%Y-%m-%d')
    content_yes= '[title="'+now_str_yes+'"]'
    order_select_time_yesterday = (By.CSS_SELECTOR,content_yes)

    # 清空时间选择
    #order_time_clear = (By.CSS_SELECTOR,'[class="antd4-picker-clear"]')
    #order_time_clear = (By.XPATH, '//*[@id="root"]/section/section/main/div/main/div/div/div/div[2]/div[1]/form/div[1]/div/div/div/div/span[2]')
    order_time_clear = (By.XPATH, '//*[@class="antd4-picker-clear"]/span')


    # 输入order_id进行查询
    # order_id_input = (By.CSS_SELECTOR,'[class="antd4-input antd4-input-status-success"]')
    order_id_input = (By.XPATH,'//*[@id="orderId"]')

    # 查询按钮
    order_search = (By.CSS_SELECTOR,'[class="antd4-btn antd4-btn-default antd4-btn-icon-only antd4-input-search-button"]')

    # 查询列表
    # 筛选产品按钮
    select_product =(By.XPATH,'//span[text()="Product"]/..//span[@role="button"]')
    # 筛选Order Type按钮
    select_order_type = (By.XPATH,'//span[text()="Order Type"]/..//span[@role="button"]')
    # 筛选Order Status按钮
    select_order_status = (By.XPATH,'//span[text()="Order Status"]/..//span[@role="button"]')
    # 筛选Billing Method按钮
    select_billing_method = (By.XPATH, '//span[text()="Billing Method"]/..//span[@role="button"]')
    # 产品列表
    product = (By.XPATH,'//*[@class="antd4-dropdown antd4-dropdown-placement-bottomRight "]//*[@class="antd4-dropdown-menu-title-content"]')
    # product的确认按钮
    product_ok = (By.XPATH,'//*[@class="antd4-dropdown antd4-dropdown-placement-bottomRight "]//*[@class="antd4-btn antd4-btn-primary antd4-btn-sm"]')
    # 查询列表
    select_list = (By.CSS_SELECTOR,'[class="antd4-table-row antd4-table-row-level-0"]')
    # product列
    product_list = (By.CSS_SELECTOR,'[class="antd4-table-row antd4-table-row-level-0"]>:nth-child(2)')
    # reset
    reset = (By.XPATH,'//*[@class="antd4-dropdown antd4-dropdown-placement-bottomRight "]//*[@class="antd4-btn antd4-btn-link antd4-btn-sm"]')

    # create_time列
    click_create_time = (By.CSS_SELECTOR,'[class="antd4-table-column-sorter-inner"]')
    # 排序按钮
    click_order = (By.XPATH,'//*[text()="Click to sort ascending"]')

    # order页面total数量
    total_items = (By.CSS_SELECTOR,'[class="antd4-pagination-total-text"]')


    """
        Export Records页面
    """
    # 下载按钮
    click_down = (By.XPATH,'//span[@class="anticon anticon-download"]')
    # 进去下载页面提示成功语
    click_down_success_cue = (By.XPATH,'//span[text()="Create asynchronous task successfully"]')
    # 进入Export Records页面
    export_records_success = (By.XPATH,'(//div[text()="Export Records"])[2]')
    # 最新一条下载数据的状态值
    first_down_load_data_status = (By.XPATH,'(//div[@class="cre-table-nowrap"])[1]/../../td[3]//span[text()="Export successful"]')
    # 最新一条下载数据的name
    first_down_load_data_name = (By.XPATH, '(//div[@class="cre-table-nowrap"])[1]')
    # 最新一条数据的下载按钮
    first_download = (By.XPATH,'(//span[text()="Download"])[1]/..')
    # status状态选择
    status_choose = (By.CSS_SELECTOR,'[class="anticon anticon-filter"]')
    # reset 按钮
    reset_point = (By.XPATH,'//span[text()="Reset"]/..')
    # OK 按钮
    ok_point = (By.XPATH,'//span[text()="OK"]/..')

